//
//  YTStashDetailsTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/18.
//

#import "YTStashDetailsTableViewCell.h"

@interface YTStashDetailsTableViewCell ()
@property (nonatomic ,strong) UIView * makeOneView;
@property (nonatomic ,strong) UILabel * nameLab;
@property (nonatomic ,strong) UILabel * productBrand;
@property (nonatomic ,strong) UILabel * stockNumber;
@property (nonatomic ,strong) UILabel * areaName;
@property (nonatomic ,strong) UILabel * addressName;
@property (nonatomic ,strong) UILabel * shelfNumber;
@property (nonatomic ,strong) UIView * makeTweView;
@property (nonatomic ,strong) UILabel * productNorms;
@property (nonatomic ,strong) UILabel * categoryName;


@end

@implementation YTStashDetailsTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * makeOneView = [UIView new];
    [DTKTool YJ:kwt(5) andView:makeOneView];
    makeOneView.backgroundColor = UIColor.whiteColor;
    self.makeOneView = makeOneView;
    [self.contentView addSubview:makeOneView];
    [makeOneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(kwt(10));
        make.right.offset(kwt(-10));
    }];

    UILabel * nameLab = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    self.nameLab = nameLab;
    nameLab.numberOfLines = 2;
    [makeOneView addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(14));
        make.top.offset(kwt(12));
        make.right.offset(kwt(-14));
    }];
    
    
    UILabel * pplab = [DTKTool labelWithText:@"品牌" andFont:kFont(13) andTextColor:KcolorHex(@"#FEF8E3")];
    pplab.textAlignment = NSTextAlignmentCenter;
    [DTKTool BFYJ:kwt(3) andView:pplab andCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft andSize:CGRectMake(0,0,kwt(32), kwt(21))];
    pplab.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(32), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#4F5680") endColor:KcolorHex(@"#252638")];
    [makeOneView addSubview:pplab];
    [pplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLab.mas_bottom).offset(kwt(10));
        make.left.offset(kwt(14));
        make.width.offset(kwt(32));
        make.height.offset(kwt(21));
    }];
    UILabel * productBrand = [DTKTool labelWithText:@"--" andFont:kFont(13) andTextColor:KcolorHex(@"#6E3E00")];
    self.productBrand = productBrand;
    productBrand.textAlignment = NSTextAlignmentCenter;
    [DTKTool BFYJ:kwt(3) andView:productBrand andCorner:UIRectCornerTopRight|UIRectCornerBottomRight andSize:CGRectMake(0,0,kwt(32), kwt(21))];
    productBrand.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(32), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#FFE5CC") endColor:KcolorHex(@"#FFEBC2")];
    [makeOneView addSubview:productBrand];
    [productBrand mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pplab.mas_right);
        make.centerY.equalTo(pplab);
        make.width.offset(kwt(32));
        make.height.offset(kwt(21));
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DBDBDB");
    [makeOneView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.right.offset(kwt(-12));
        make.height.offset(0.5);
        make.top.equalTo(nameLab.mas_bottom).offset(kwt(41));
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"库存数量" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeOneView addSubview:templab1];
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLab.mas_bottom).offset(kwt(52));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * stockNumber = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeOneView addSubview:stockNumber];
    self.stockNumber = stockNumber;
    [stockNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab1);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
    }];
    
    UILabel * templab2 = [DTKTool labelWithText:@"仓库区域" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeOneView addSubview:templab2];
    [templab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(stockNumber.mas_bottom).offset(kwt(16));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * areaName = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeOneView addSubview:areaName];
    self.areaName = areaName;
    [areaName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab2);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
    }];
    
    UILabel * templab3 = [DTKTool labelWithText:@"存放位置" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeOneView addSubview:templab3];
    [templab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(areaName.mas_bottom).offset(kwt(16));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * addressName = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeOneView addSubview:addressName];
    addressName.numberOfLines = 0;
    self.addressName = addressName;
    [addressName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab3);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
    }];
    
    UILabel * templab4 = [DTKTool labelWithText:@"货架号" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeOneView addSubview:templab4];
    [templab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addressName.mas_bottom).offset(kwt(16));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * shelfNumber = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeOneView addSubview:shelfNumber];
    self.shelfNumber = shelfNumber;
    [shelfNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab4);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
        make.bottom.offset(kwt(-16));
    }];
    
    UIView * makeTweView = [UIView new];
    [DTKTool YJ:kwt(5) andView:makeTweView];
    makeTweView.backgroundColor = UIColor.whiteColor;
    self.makeTweView = makeTweView;
    [self.contentView addSubview:makeTweView];
    [makeTweView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(makeOneView.mas_bottom).offset(kwt(10));
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
    }];
    
    
    UILabel * templab5 = [DTKTool labelWithText:@"规格/单位" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeTweView addSubview:templab5];
    [templab5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(16));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * productNorms = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeTweView addSubview:productNorms];
    self.productNorms = productNorms;
    [productNorms mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab5);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
    }];
    
    UILabel * templab6 = [DTKTool labelWithText:@"物品品类" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [makeTweView addSubview:templab6];
    [templab6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(productNorms.mas_bottom).offset(kwt(16));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * categoryName = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [makeTweView addSubview:categoryName];
    self.categoryName = categoryName;
    [categoryName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(templab6);
        make.left.offset(kwt(97));
        make.width.offset(kwt(240));
        make.height.offset(kwt(16));
        make.bottom.offset(kwt(-16));
    }];
    

}


-(void)setModel:(YTStashListModel *)model{
    _model = model;
    self.nameLab.text = model.name;
    [self.nameLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.BTnameH);
    }];
    self.productBrand.text = model.productBrand;
    CGFloat productBrandW = [DTKTool textWithtitle:model.productBrand andSize:CGSizeMake(1000, 100) andFout:kFont(13)].width + kwt(8);
    if(productBrandW > kwt(220)){
        productBrandW = kwt(220);
    }
    [self.productBrand mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(productBrandW);
    }];
    [DTKTool BFYJ:kwt(3) andView: self.productBrand andCorner:UIRectCornerTopRight|UIRectCornerBottomRight andSize:CGRectMake(0,0,productBrandW, kwt(21))];

    self.stockNumber.text = model.stockNumberStr;
    [self.stockNumber mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.stockNumberH);
    }];
    self.areaName.text = model.areaName;
    [self.areaName mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.areaNameH);
    }];
    self.addressName.text = model.addressName;
    [self.addressName mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.addressNameH);
    }];
    self.shelfNumber.text = model.shelfNumber;
    [self.shelfNumber mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.shelfNumberH);
    }];
    self.productNorms.text = model.productNormsStr;
    [self.productNorms mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.productNormsStrH);
    }];
    self.categoryName.text = model.categoryName;
    [self.categoryName mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.categoryNameH);
    }];
    
}

@end
